package com.itheima.health.controller.mobile;

import com.itheima.health.common.MessageConst;
import com.itheima.health.dto.SmsLoginParam;
import com.itheima.health.result.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author
 */
@RestController
@RequestMapping("/mobile/login")
public class SmsLoginController {


    @Autowired
    private RedisTemplate  redisTemplate;
    @PostMapping("/smsLogin")
    public Result  login(@RequestBody SmsLoginParam smsLoginParam){
        String telephoneRedis = (String) redisTemplate.opsForValue().get("telephone");
        String codeRedis = (String) redisTemplate.opsForValue().get("code");
        if (telephoneRedis.equals(smsLoginParam.getTelephone()) && codeRedis.equals(smsLoginParam.getValidateCode())){
            return  new Result(true, MessageConst.LOGIN_SUCCESS);
        }
            return  new Result(false, MessageConst.LOGIN_FAIL);

    }
}
